<?php

namespace App\Http\Controllers\Admin;

use App\Models\Menu;
use App\Utils\CodeEnumUtils;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

/**
 * 菜单管理
 * Class MenuController
 * Author: Albert3306
 * Date: 2020/9/11
 * @package App\Http\Controllers\Admin
 */
class MenuController extends BaseController
{
    /**
     * 菜单表展示页
     * Author: Albert3306
     * Date: 2020/8/7
     * @return Factory|View
     */
    public function index()
    {
        return view('admin.menu.index')->with(['title' => '菜单列表']);
    }

    /**
     *
     * Author: Albert3306
     * Date: 2020/8/7
     * @param Request $request
     * @return JsonResponse
     */
    public function getMenus(Request $request)
    {
        // 构建查询
        $menu = new Menu();
        if ($request->keywords) {
            $menu = $menu->where('name', 'like', '%' . $request->keywords . '%');
        }
        if (isset($request->status)) {
            $menu = $menu->where('is_show', $request->status);
        }

        return CodeEnumUtils::response(200, $menu->get());
    }
}
